<template>
		<modal-container v-el:modal title="编辑" class="edit-modal">
		<form v-el:submitform @submit.prevent>
			<div>
				<table class="table table-hover">
					<tbody>
							<tr>
								<td>商户名称</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtName"  name="mchtName">
								</td>
							</tr>
							<tr>
								<td>入驻时间</td>
								<td>
									<input type="text" class="form-control" :value="model.enterTime"  name="enterTime">
								</td>
							</tr>
							<tr>
								<td>商户地址</td>
								<td>
									<textarea type="text" class="form-control" rows="3" name="mchtAddr" maxlength="50"  style="resize:none">{{model.mchtAddr}}</textarea>
								</td>
							</tr>
							<tr>
								<td>营业日</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtBusDay"  name="mchtBusDay">
								</td>
							</tr>
							<tr>
								<td>营业日2</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtBusDay2"  name="mchtBusDay2">
								</td>
							</tr>
							<tr>
								<td>营业时间段</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtBusTime"  name="mchtBusTime">
								</td>
							</tr>
							<tr>
								<td>营业时间段2</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtBusTime2"  name="mchtBusTime2">
								</td>
							</tr>
							<tr>
								<td>营业时间段2</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtBusTime2"  name="mchtBusTime2">
								</td>
							</tr>
							<tr>
								<td>商户描述</td>
								<td>
									<textarea type="text" class="form-control" rows="3" name="mchtDsc" maxlength="50"  style="resize:none">{{model.mchtDsc}}</textarea>
								</td>
							</tr>
							<tr>
								<td>设备</td>
								<td>
									<select type="text" class="form-control" :value="model.mchtEQuip"  name="mchtEQuip">
										<option value="0">是</option>
										<option value="1">否</option>
									</select>
								</td>
							</tr>
							<tr>
								<td>商户级别</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtLvl "  name="mchtLvl">
								</td>
							</tr>
							<tr>
								<td>人均消费</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtPer"  name="mchtPer">
								</td>
							</tr>
							<tr>
								<td>商户别名</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtRName"  name="mchtRName">
								</td>
							</tr>
							<tr>
								<td>商户电话1</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtLvl"  name="mchtLvl">
								</td>
							</tr>
							<tr>
								<td>商户电话2</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtLv2"  name="mchtLv2">
								</td>
							</tr>
							<tr>
								<td>商户电话3</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtLv3"  name="mchtLv3">
								</td>
							</tr>
							<tr>
								<td>商户电话其他</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtLv4"  name="mchtLv4">
								</td>
							</tr>
							<tr>
								<td>商户类型</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtType"  name="mchtType">
								</td>
							</tr>
							<tr>
								<td>二级分类</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtType2"  name="mchtType2">
								</td>
							</tr>
							<tr>
								<td>节日</td>
								<td>
									<select type="text" class="form-control" :value="model.streamDbt"  name="streamDbt">
									</select>
								</td>
							</tr>
							<tr>
								<td>上级商户编号</td>
								<td>
									<select type="text" class="form-control" :value="model.upperMchtId"  name="upperMchtId">
									</select>
								</td>
							</tr>



							<!-- <tr>
								<td>商户邮编</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtPostCd"  name="mchtPostCd">
								</td>
							</tr>
							<tr>
								<td>商户电话</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtTel"  name="mchtTel">
								</td>
							</tr>															 													 																	 		 -->
					</tbody>
				</table>
			</div>
			<div class="modal-footer">
				<v-button type="submit" theme="primary" class="pull-left">确认</v-button>
				<v-button @click="hide">取消</v-button>
			</div>
		</form>
		</modal-container>

</template>

<script>

	let serialize = require('form-serialize');
	import 'assets/script/bootstrap-maxlength.js'

	export default {
		props: {
			model: {
			  type: Object,
				default:{}
			}
		},
		data:()=>({
			collection: {
				role: [],
				mchtEQuip:[
						{key: "有",value: "0"},
						{key: "没有",value: "1"},
				],
				streamDbt:[
						{key: "节假日",value: "0"},
						{key: "工作日",value: "1"},
				],
			}
		}),
		methods: {
			  init() {
					$(this.$els.modal).modal("show");
				},
		  	hide() {
					$(this.$els.modal).modal("hide");
				},
				_selected(roleId) {
					return (roleId == this.model.roleId);
				},
		    reload() {
					this.$dispatch("table-reload");
				},
				submit(data) {
					let self = this;
					data.brhNoFlag = this.model.id.brhNo;
					self.$post({
						url: "/api/v2" + projectName_Url + "/plat/mcht/{mchtId}",
						method: "PUT",
						data
					}).then(response => {
						let data = {
							title: "操作提示",
							content: "编辑操作成功"
						}
						Midway.alert(data);
						self.hide();
						self.reload();
					}, response => {

					});
				}
	 },
	 ready() {
		 let self = this;

			$(this.$els.submitform).submit(function () {
				return false;
			});
		  $(self.$els.submitform).validate({
			 submitHandler() {
					let form = this.currentForm;

					$(form).find("input").each(function () {
						$(this).val($.trim($(this).val()));
					});

					let _data = serialize(form, {
							hash: true,
						  disabled: true,
						  empty: true
					});

					//_data = Object.assign(self.model, _data);

				  // _data.mchtId   = self.model.id.mchtId;
				  self.submit(_data);

			 },
				rules: {
					// mchtId: {
					// 	required: true,
					// 	number: true,
					// 	int: true,
					// 	maxlength: 16
					// },
					mchtName: {
						required: true,
						maxlength: 16
					},
					mchtAddr: {
						required: true,
						maxlength: 50
					},
					mchtPostCd: {
						required: true,
						isZipCode: true
					},
					mchtTel: {
						required: true,
						isTel: true
					},
					enterTime: {
						required: true,
					},
					mchtArea: {
						required: true,
					},
					mchtBusDay: {
						required: true,
					},
					mchtBusTime: {
						required: true,
					},
					mchtLvl: {
						required: true,
					},
					mchtPer: {
						required: true,
					},
					mchtType: {
						required: true,
					},
					mchtTel1: {
						required: true,
						maxlength: 11,
						number: true,
						int: true,
					}
				},
				messages: {
					mchtName: {
						required: "商户名为必填项",
						maxlength: "商户名不多于16字"
					},
					enterTime: {
						required: "入驻时间为必填项"
					},
					mchtAddr: {
						required: "商户地址为必填项",
						maxlength: "商户地址不多于50字"
					},
					mchtArea: {
						required: "地址为必填项"
					},
					mchtBusDay: {
						required: "营业日为必填项"
					},
					mchtBusTime: {
						required: "营业时间段为必填项"
					},
					mchtLvl: {
						required: "商户级别段为必填项"
					},
					mchtPer: {
						required: "人均消费为必填项",
					},
					mchtType: {
						required: "商户类型为必填项",
					},
					mchtTel1: {
						required: "商户电话为必填项",
					}
				}
		 });

		  $('input[maxlength]').maxlength();
	 }
}
</script>
<style media="screen">

</style>
